package GAME;

import java.util.*;

public class Game {
    //玩家个数
    int playerNumber;

    //玩家信息（角色 ip地址 昵称）
    class Player{
        int role;
        String ip;
        String name;
    };
    Player[] player;
    int[] chosenNumber = new int[]{2,3,4,3,4};
    Scanner scan = new Scanner(System.in);

    Game(){}
    Game(int playerNumber, Vector<String> ips, Vector<String>names){
        this.playerNumber = playerNumber;
        player = new Player[playerNumber];
        InitPlayer(ips, names);
    }

    //初始化player[]
    void InitPlayer(Vector<String> ips, Vector<String>names){
        int cnt = 0;
        for(String s :ips){
            player[cnt].ip = s;
        }
        cnt = 0;
        for(String s :names){
            player[cnt].name = s;
        }

        int[] vis = new int[playerNumber];
        Random rand = new Random();
        for(int i = 0 ; i < playerNumber ; i++){
            int num = rand.nextInt(playerNumber - i);
            int chose = 0;
            for(int j = 0 ; j < num ; j++){
                if(vis[chose] == 1)j--;
                chose++;
            }
            while(vis[chose] == 1)chose++;
            vis[chose] = 1;
            player[i].role = chose;
            System.out.println("Player " + i + "'s id = " + chose);
        }
    }

    //游戏运行
    void Run(){
        int win = 0;
        for(int i = 0 ; i < 5 ; i++){
            Set<Integer> st = new HashSet<>();
            do {
                st = ChooseSet(i);
            } while (Vote(st) == false);
            if(Solve(st) == true)win++;
        }
        if(win >= 3) System.out.println("刺客刀人");
        else System.out.println("坏人胜利");
    }

    //房主选人
    Set<Integer> ChooseSet(int round){
        Set<Integer>st = new HashSet<Integer>();
        while (st.size() != chosenNumber[round]){
            System.out.println(String.format("为第%d个任务选择%d名队员", round + 1, chosenNumber[round]));
            st.clear();
            for(int j = 0 ; j < chosenNumber[round] ; j++){
                st.add(scan.nextInt());
            }
        }
        return st;
    }

    //是否同意本次选人
    boolean Vote(Set<Integer>st){
        int agree = 0;
        for(int i = 0 ; i < playerNumber ; i++){
            if(AskPlayer(i,st) == true) agree++;
        }
        return agree + agree > playerNumber;
    }

    //上车人是否炸车
    boolean Solve(Set<Integer>st){
        boolean ok = true;
        for(Integer id : st){
            if(AskPlayer(id) == false) ok = false;
        }
        return ok;
    }

    boolean AskPlayer(int i){
        return true;
    }
    boolean AskPlayer(int i, Set<Integer>st){
        return true;
    }
}
